﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hover.Repository
{
    public class PagedList<T> : List<T>, IPagedList<T>
    {
        public PagedList(IQueryable<T> source, int index, int pageSize)
        {
            this.TotalCount = source.Count();
            this.PageSize = pageSize;
            this.PageIndex = index;
            this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
        }
        public PagedList(List<T> source, int index, int pageSize)
        {
            this.TotalCount = source.Count();
            this.PageSize = pageSize;
            this.PageIndex = index;
            this.AddRange(source.Skip(index * pageSize).Take(pageSize).ToList());
        }
        #region IPagedList Members

        public int TotalCount
        { get; set; }

        public int PageIndex
        { get; set; }

        public int PageSize
        { get; set; }

        public bool IsPreviousPage
        {
            get { return (PageIndex > 0); }
        }

        public bool IsNextPage
        {
            get { return (PageIndex * PageSize) <= TotalCount; }
        }

        #endregion
    }
}

